<template>
	<view :class="isDark?'darkBg':''">

		<cu-custom :bgColor="isDark?'bg-black':'bg-blue'" isBack="true">
			<block slot="backText">返回</block>
			<block slot="content">实习打卡</block>
		</cu-custom>
		<view style="height: 545rpx; background-size: cover;  background-position: center;"
			:style="{backgroundImage:isDark?'url(https://web.cloudduolc.cn/image/adblack7.png)':'url(https://web.cloudduolc.cn/image/adwhite5.png)'}">
			<ad unit-id="adunit-44140b632687f8e4" ad-type="video" :ad-theme="isDark?'black':'white'"></ad>
		</view>
		<view class="cu-bar  solid-bottom" style="font-weight:bold" :class="isDark?'dark':'bg-white'">
			<view class="action">
				<text class="cuIcon-titles text-blue"></text> 实习打卡
			</view>

			<view class="padding flex flex-wrap margin-left-sm">
				<button class="cu-btn round line margin-right-xl" :class="isDark?'dark':''"
					@click="subscribe()">订阅打卡提醒</button>
				<button class="cu-btn round line" @click="getList()"><text class="cuIcon-refresh text-right"
						:class="isDark?'dark':'bg-white'"></text></button>
			</view>
		</view>

		<view class="text-center text-grey  menu card-menu" :class="isDark?'dark':'bg-white'">

			<view class="cu-bar btn-group">
				<button class="cu-btn bg-olive xxl" @click="clock()">上班打卡</button>
				<button class="cu-btn bg-red xxl" @click="clock()">下班打卡</button>
			</view>

		</view>
		<view class="cu-timeline" :class="isDark?'dark':'bg-white'">
			<navigator class="padding flex flex-direction" url="/pages/school/internship/info">
				<button class="cu-btn line-grey lg" :style="isDark?'color:white':'color:gray'">修改信息</button>
			</navigator>
			<view class="cu-item text-green" v-for="(val,index) in totalList" :key="index"
				:class="isDark?'dark':'bg-white'">
				<view class="bg-gradual-green content shadow">
					<view class="margin-top-sm text-content">
						<view>{{index+1}}</view>
						<view>打卡时间：{{val.QDSJ}}</view>
						<view>打卡地址：{{val.QDXXDZ}}</view>
					</view>
				</view>
			</view>
			<view style="text-align: center;padding-bottom: 50rpx;" class="text-gray">(最多显示最近十条打卡记录)</view>


		</view>
		<view v-if="totalList.length<=0" style="text-align: center;font-size: 40rpx;"
			class="margin-left margin-right margin-top" :class="isDark?'darkIn':'bg-white'">


			<image src="../../../static/score/empty.png" style="width: 600rpx;height: 600rpx;margin-top: 0rpx;">
			</image>
		</view>
		<zmm-watermark>

		</zmm-watermark>
	</view>

</template>
<script>
	export default {
		data() {
			return {
				isDark: this.isDark,
				totalList: [],
				showEmpty: false,
				smallPlace: "",
				bigPlace: ""

			}
		},
		onShow() {
			this.getList()
		},
		methods: {
			subscribe() {
				let _this = this
				wx.requestSubscribeMessage({
					tmplIds: ['rmj0JJ0jHneJGdghVcBY9zsRTCzg-3J-Pv3axKbgEJc'],
					success(res) {
						console.log(res)
						if (res['rmj0JJ0jHneJGdghVcBY9zsRTCzg-3J-Pv3axKbgEJc'] == 'accept') {
							_this.$schoolApi.internshipAddRemind(null).then(function(response) {
								console.log(response)
								if (response.status == 0) {
									uni.showToast({
										title: '订阅一次成功，可累加',
										icon: 'none'
									})

								} else if (response.status != 608 && response.status != 603) {
									uni.showModal({
										title: '提示',
										content: response.msg,
										showCancel: false,
										success: function(res) {
											if (res.confirm) {

											} else if (res.cancel) {

											}
										}
									});
								}

								//这里只会在接口是成功状态返回
							}).catch(function(error) {
								//这里只会在接口是失败状态返回，不需要去处理错误提示
								console.log(error);
							});
						} else {
							uni.showToast({
								title: '取消订阅',
								icon: 'none'
							})
						}

					},
					fail(res) {
						console.log(res)
						uni.showToast({
							title: '订阅失败',
							icon: 'none'
						})
					}
				})

			},
			clock() {
				let _this = this
				_this.subscribe()
				var userInfo = _this.$store.state.userInfo
				console.log(_this.$store.state.isExit)
				if ((_this.$store.state.isExit == 1 | userInfo.password == "" | userInfo.password == null) && _this
					.$store.state.loginTip == null) {
					_this.$store.commit("loginTip", "1")
					uni.showModal({
						title: 'Hi',
						content: '会话已过期，\n当前功能需要登录，是否要去登录?\n(该程序的用户信息只存在手机本地，当切出程序需要重新登录)',
						confirmText: "去登录",
						cancelText: "再逛会",
						success: function(res) {
							_this.$store.commit("loginTip", null)
							if (res.confirm) {
								_this.$Router.navigateTo("/pages/bind/login/index")
							} else if (res.cancel) {
								console.log("点击了取消")
							} else {
								console.log("点击了别的")
							}
						}
					});
					return
				}


				if (_this.smallPlace.length <= 0 && _this.$store.state.internshipPlace.sInfo == undefined) {
					uni.showModal({
						title: '提示',
						content: '当前未识别到你的打卡地址',
						confirmText: "去填写",
						cancelText: "再逛会",
						success: function(res) {
							if (res.confirm) {
								_this.$Router.navigateTo("/pages/school/internship/info")
							} else if (res.cancel) {
								console.log("点击了取消")
							} else {
								console.log("点击了别的")
							}
						}
					});
					return
				}
				if (_this.$store.state.internshipPlace.sInfo != undefined) {
					_this.bigPlace = _this.$store.state.internshipPlace.sfInfo + ", " + _this.$store.state.internshipPlace
						.sInfo + ", " + _this.$store.state.internshipPlace.qInfo
					_this.smallPlace = _this.$store.state.internshipPlace.smallPlace


					if (_this.$store.state.internshipPlace.smallPlace.indexOf(_this.$store.state.internshipPlace.sfInfo) ==
						-1) {
						uni.showToast({
							icon: 'none',
							title: '省份信息不相同，去修改',
							duration: 2000
						});
						return
					}
					if (_this.$store.state.internshipPlace.smallPlace.indexOf(_this.$store.state.internshipPlace.sInfo) ==
						-1) {
						uni.showToast({
							icon: 'none',
							title: '市的信息不相同，去修改',
							duration: 2000
						});
						return
					}
					if (_this.$store.state.internshipPlace.smallPlace.indexOf(_this.$store.state.internshipPlace.qInfo) ==
						-1) {
						uni.showToast({
							icon: 'none',
							title: '区的信息不相同，去修改',
							duration: 2000
						});
						return
					}
				}



				let form = {
					password: _this.$store.state.userInfo.password,
					smallPlace: _this.smallPlace,
					bigPlace: _this.bigPlace
				}
				uni.showModal({
					title: '提示',
					content: '是否打卡,地址为:' + _this.smallPlace,
					success: function(res) {
						if (res.confirm) {
							_this.$schoolApi.internshipSign(form).then(function(response) {
								console.log(response)
								if (response.status == 0) {
									uni.showToast({
										icon: 'none',
										title: response.data.msg,
										duration: 2000
									});
									_this.getList()

								} else if (response.status != 608 && response.status != 603) {
									uni.showModal({
										title: '提示',
										content: response.msg,
										showCancel: false,
										success: function(res) {
											if (res.confirm) {

											} else if (res.cancel) {

											}
										}
									});
								}

								//这里只会在接口是成功状态返回
							}).catch(function(error) {
								//这里只会在接口是失败状态返回，不需要去处理错误提示
								console.log(error);
							});
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				});


			},

			getList() {
				let _this = this
				var userInfo = _this.$store.state.userInfo
				console.log(_this.$store.state.isExit)
				if ((_this.$store.state.isExit == 1 | userInfo.password == "" | userInfo.password == null) && _this
					.$store.state.loginTip == null) {
					_this.$store.commit("loginTip", "1")
					uni.showModal({
						title: 'Hi',
						content: '会话已过期，\n当前功能需要登录，是否要去登录?\n(该程序的用户信息只存在手机本地，当切出程序需要重新登录)',
						confirmText: "去登录",
						cancelText: "再逛会",
						success: function(res) {
							_this.$store.commit("loginTip", null)
							if (res.confirm) {
								_this.$Router.navigateTo("/pages/bind/login/index")
							} else if (res.cancel) {
								console.log("点击了取消")
							} else {
								console.log("点击了别的")
							}
						}
					});
					return
				}



				let form = {
					password: _this.$store.state.userInfo.password,
				}
				_this.$schoolApi.internshipList(form).then(response => {
					//console.log(response.data)
					if (response.status == 0) {
						uni.showToast({
							icon: 'none',
							title: '成功获取数据',
							duration: 2000
						});
						if (response.data.data == '[]') {
							return
						}
						_this.totalList = response.data.datas.cxxsqd.rows
						var list = []
						for (var i = _this.totalList.length - 1; i >= 0; i--) {
							list.push(_this.totalList[i])
						}
						_this.totalList = list
						_this.smallPlace = list[0].QDXXDZ



					} else if (response.status != 608 && response.status != 603) {
						uni.showModal({
							title: '提示',
							content: response.msg,
							showCancel: false,
							success: function(res) {
								if (res.confirm) {

								} else if (res.cancel) {

								}
							}
						});
					}

					//这里只会在接口是成功状态返回
				}).catch(function(error) {
					//这里只会在接口是失败状态返回，不需要去处理错误提示
					console.log(error);




				});
			}
		}
	}
</script>

<style>


</style>
